import { defineAsyncComponent, type App } from 'vue';

export default {
  install: (app: App) => {
    // 1. 获取当前路径下所有文件夹中的 index.ts
    const components = import.meta.glob('./*/index.ts');

    // 2. 遍历获取到的组件模块
    for (const [filepath, fn] of Object.entries(components)) {
      // 3.利用 app.component 注册
      const componentName = `M${filepath.replace('./', '').split('/')[0]}`;
      app.component(
        componentName,
        defineAsyncComponent(async () => (await fn()) as any)
      );
    }
  }
};

export { default as MButton } from './Button';

export { Confirm as MConfirm } from './Confirm';

export { default as MInfinite } from './Infinite';

export { Message as MMessage } from './Message';

export { default as MPopover } from './Popover';

export { default as MPopup } from './Popup';

export { default as MSearch } from './Search';

export { default as MSvgIcon } from './SvgIcon';

export { default as MWaterfall } from './Waterfall';
